package de.maxbuttlies.playlistmaker;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;

public class PlayListMaker {
	public String getPlayListName(Map<String, String> params) {
		String playListName;
		if (!params.containsKey("-n")) {
			String folderPath = System.getProperty("user.dir");
			playListName = new File(folderPath).getName();
		} else {
			playListName = params.get("-n");
		}
		if (params.containsKey("-b") && params.containsKey("-a")) {
			playListName = params.get("-b") + " - " + params.get("-a");
		}

		return playListName;
	}

	public void writePlayList(String playListName, String[] entries, File dir,
			Map<String, String> params) {
		try {
			FileWriter writer = new FileWriter(dir + "\\" + playListName
					+ ".m3u");
			for (int i = 0; i < entries.length; i++) {
				if (params.containsKey("-p")) {
					if (params.get("-p").equals("true")) {
						String folderPath = System.getProperty("user.dir");
						System.out.println(folderPath + "\\" + entries[i]
								+ "\n");
						writer.write(folderPath + "\\" + entries[i] + "\n");
						writer.flush();
					}
				} else {
					System.out.println(entries[i] + "\n");
					writer.write(entries[i] + "\n");
					writer.flush();
				}

			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
